﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 添加待选课程
            listBox1.Items.Add("VB程序设计");
            listBox1.Items.Add("C#程序设计");
            listBox1.Items.Add("数据库技术与应用");
            listBox1.Items.Add("硬件技术基础");
            listBox1.Items.Add("Web程序设计");
            listBox1.Items.Add("多媒体技术与应用");
            listBox1.Items.Add("网络技术与应用");
            listBox1.Items.Add("软件工程");
            listBox1.Items.Add("大学计算机基础");
            // 启用排序
            listBox1.Sorted = true;
            listBox2.Sorted = true;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null) return;
            if (listBox2.Items.Count >= 5)
            {
                MessageBox.Show("对不起，您最多只能选5门课！", "提示");
                return;
            }
            // 移动课程
            listBox2.Items.Add(listBox1.SelectedItem);
            listBox1.Items.Remove(listBox1.SelectedItem);
        }

        private void listBox2_DoubleClick(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem == null) return;
            listBox1.Items.Add(listBox2.SelectedItem);
            listBox2.Items.Remove(listBox2.SelectedItem);
        }
    }
}
